package com.distribute.application.manage;

import com.distribute.framework.core.web.helper.Utils;
import com.distribute.framework.core.xwork.WebContext;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.*;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.distribute.framework.model.Manage;
import com.distribute.framework.model.Merchant;

public class LoginHelper{

	private static String manage_login="manage_login";
	private static String manage_user="manage_user";

	public static void setLogin(Merchant login) {
		if(login!=null){
			Utils.setCookie("/", manage_login, login.getId()+"-"+Utils.md5("ASDFGHJKL"+login.getId()));
		}
		Utils.setSession(manage_login, login);
	}
	
	public static Merchant getLogin(){ 
		Merchant login = (Merchant)Utils.getSession(manage_login);
		return login;
	}

	public static Long getUserId() {
		return getLogin().getId();
	}

	public static void setUser(Manage user) {
		if(user!=null){
			Utils.setCookie("/", manage_user, user.getId()+"-"+Utils.md5("ASDFGHJKL"+user.getId()));
		}
		Utils.setSession(manage_user, user);
	}
	public static Manage getUser(){
		Manage user = (Manage)Utils.getSession(manage_user);
		return user;
	}
	
}